﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;

namespace TJADRICD.CollaborativeDesignPlugin
{
    public class CommandCUI
    {
        [CommandMethod("addcui", CommandFlags.Session)] //加载局部CUI
        public void addcui()
        {
            string flName = @"C:\autocad\tjadri.cui";
            Application.SetSystemVariable("FILEDIA", 0);//文件对话框开关设置0-文本方式，1-对话框方式
            try
            {
                Application.DocumentManager.MdiActiveDocument.SendStringToExecute("cuiload " + flName + " ", false, false, false);
            }
            catch (System.Exception e)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.ToString());
            }
            finally
            {
                Application.SetSystemVariable("FILEDIA", 1);
            }

        }
        [CommandMethod("delcui", CommandFlags.Session)] //卸载局部CUI
        public void delcui()
        {
            try
            {
                Application.SetSystemVariable("FILEDIA", 0);//文件对话框开关设置
                //卸载时需注意，cuiunload 后面跟的是菜单组名，请用记事本打开你建立的局部CUI文件查看
                //例如，hello.cui用记事本打开后可以看到  <MenuGroup Name="HELLO">
                Application.DocumentManager.MdiActiveDocument.SendStringToExecute("cuiunload " + "tjadri ", false, false, false);
            }
            catch (System.Exception e)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.ToString());
            }
            finally
            {
                Application.SetSystemVariable("FILEDIA", 1);
            }
        }
    }
}
